// Learn cc.Class:
//  - https://docs.cocos.com/creator/manual/en/scripting/class.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

cc.Class({
    extends: cc.Component,

    properties: {
        dragonboneNode : { //龙骨动画节点
            default : null,
            type : cc.Node,
        },
        armatureDisplay : { //龙骨动画
            default : null,
            type : dragonBones.ArmatureDisplay,
        },
        postionAnimation : { //位移动画
            default : null,
            type : cc.Animation,
        },
        chirpSound:{
            default:null,
            type:cc.AudioClip
        }
    },

    onLoad () {
           //龙骨动画
           this.armatureDisplay = this.dragonboneNode.getComponent(dragonBones.ArmatureDisplay);
           //位移动画
           this.postionAnimation = this.dragonboneNode.getComponent(cc.Animation);
           //位移动画状态
           let animState = this.postionAnimation.getAnimationState('鹤位移');
        //    animState.repeatCount = 2

           this.postionAnimation.on('finished', () => {
                // 监听位移动画结束， 动画状态也能进行监听
                console.log("移动画结束")
                this.armatureDisplay.playAnimation("站立",0)
                // this.dragonboneNode.scaleX = -0.2
                // this.postionAnimation.play()
            }, this);
    },
    walkAction(){
        this.node.active = false
        let animState = this.postionAnimation.getAnimationState('鹤位移');
        this.armatureDisplay.playAnimation("走路",0)
        if(animState&&animState.isPaused){
            this.postionAnimation.resume()
        }else{
            this.postionAnimation.play()
        }
    },
    chirpAction(){
        this.node.active = false
        let animState = this.postionAnimation.getAnimationState('鹤位移');
        if(animState&&animState.isPlaying){
            this.armatureDisplay.playAnimation("鸣叫",0)
            cc.audioEngine.play(this.chirpSound,false,1)
            this.postionAnimation.pause()
        }
    },
    standAction(){
        this.node.active = false
        this.node.active = false
        let animState = this.postionAnimation.getAnimationState('鹤位移');
        if(animState&&animState.isPlaying){
            this.armatureDisplay.playAnimation("站立",0)
            this.postionAnimation.pause()
        }

    },
    start () {

    },
});
